< previous page page_253 next page >

Page 253
Note that this code does not need to know what kind of sprite object it is using. The entries in the Sprites array can be from the BallSprite, TriangleSprite, or RectangleSprite class. As long as the entries are all from classes that implement the generic Sprite class, the program can use their MoveSprite and DrawSprite methods.
e10a6a0a59f035e870d90cca05b85fce.gif
Private NumSprites As Integer
Private Sprites() As Sprite

' Play the animation.
Private Sub PlayImages(ByVal ms_per_frame As Long)
Dim sprite_number As Integer
Dim next_time As Long

    ' Get the current time.
    next_time = GetTickCount()

    ' Start the animation.
    Do While Playing
        NumPlayed = NumPlayed + 1

        ' Restore the background.
        SetBitmapBits picCanvas.Image, _
            BitmapNumBytes, Bytes(1, 1)

        ' Draw and move the sprites.
        For sprite_number = 1 To NumSprites
            Sprites(sprite_number).DrawSprite picCanvas
            Sprites(sprite_number).MoveSprite _
                xmin, xmax, ymin, ymax
        Next sprite_number

        ' Wait until it's time for the next frame.
        next_time = next_time + ms_per_frame
        WaitTill next_time
    Loop
End Sub
Sprites make it easier to manage many different kinds of graphic objects, but they do come at a price. Calling the sprite methods slows the animation. In some cases, the extra overhead required to use sprites may make the program too slow to be usable. If your program can display only five frames per second, you should probably consider rewriting it. You might need to move sprite data into global variables and execute the moving and drawing code in the PlayImages subroutine rather than in sprite subroutines.
Tweening and Morphing
In traditional cartoon animation, all the frames are sketched, cleaned up, inked, and colored by hand. A feature-length animation might run 70 or 80 minutes. At one to two

 
< previous page page_253 next page >